home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Unix / findi.1.0 / findi.sh < prev   
Linux/UNIX/POSIX Shell Script  |  1996-04-08  |  4KB  |  214 lines

  1. #!/bin/sh
  2. name=`basename $0`
  3.  
  4. #############################################################################
  5. # AUTHOR:  Timothy J. Luoma <luomat@capitalist.princeton.edu>
  6. #
  7. # VERSION: 1.0.0
  8. #
  9. # DATE:    09 April 1996
  10. #
  11. # WARNING: USE ENTIRELY AT YOUR OWN RISK
  12. #
  13. # PURPOSE: to make using the extended flags of 'find' a little easier
  14. #        by entering into an interactive mode for some common flags
  15. #
  16. # TESTED UNDER: NeXTStep 3.2 on my NeXTStation
  17. #
  18. # USAGE NOTES:
  19. #     All arguments given are ignored
  20. #
  21. #     If you do not want to set any of the options, just hit ENTER
  22. #
  23. #     It assumes you know _something_ about how 'find' works
  24. #
  25. #    Not all flags are available, basically the ones I like
  26. #
  27. #############################################################################
  28. echo -n "$name: what directory? (Press enter to select current directory) "
  29. read dir
  30.  
  31. if [ "$dir" = "" ]
  32. then
  33.     dir="."
  34. else
  35.     if [ -d "$dir" ]
  36.     then
  37.         : #placeholder
  38.     else
  39.         echo "$name error: $dir is not a dir, using . "
  40.     fi
  41. fi
  42.  
  43. ######################################################
  44. echo -n "$name: what filename?  (Press enter for ALL) " 
  45. read filename
  46.  
  47. all=no
  48.  
  49. if [ "$filename" = "" ]
  50. then
  51.     # filename1="-name *"
  52.     all=yes
  53. else
  54.     filename1="-name $filename"
  55.     
  56.     echo -n "    Only exact matches to $filename? [y/N] " 
  57.         stty cbreak
  58.         wildcard=`dd if=/dev/tty bs=1 count=1 2>/dev/null`
  59.         stty -cbreak
  60.  
  61.         case $wildcard in
  62.             y|Y) wildcard=no
  63.             ;;
  64.  
  65.             *)   wildcard=yes
  66.             ;;
  67.         esac
  68. fi
  69.  
  70. ######################################################
  71. echo "$name: what type?"
  72. echo -n "    (d)irectory (f)ile (l)ink (s)ocket (b)lock (c)haracter (p)ipe -> "
  73.     stty cbreak
  74.     type=`dd if=/dev/tty bs=1 count=1 2>/dev/null`
  75.     stty -cbreak
  76.  
  77.     case $type in
  78.         b|c|d|f|p|l|s) 
  79.             type1="-type $type"
  80.             echo " "
  81.         ;;
  82.         
  83.         *) #no type specified
  84.             type1=""
  85.         ;;
  86.     esac
  87.  
  88. ######################################################
  89. echo -n "$name: what user? "
  90. read user
  91.  
  92.     if [ "$user" = "" ]
  93.     then
  94.         user1=""
  95.     else
  96.         user1="-user $user"
  97.     fi
  98.  
  99. ######################################################
  100. echo -n "$name: last a)ccess m)odified c)hanged? "
  101.     stty cbreak
  102.     amc=`dd if=/dev/tty bs=1 count=1 2>/dev/null`
  103.     stty -cbreak
  104.     
  105.     case $amc in
  106.         a|m|c)  
  107.             echo " "
  108.             echo -n "    how many days? (use + and -) "
  109.             read days
  110.             
  111.             if [ "$amc" = "a" ]
  112.             then
  113.                 amc1="-atime $days"
  114.             elif [ "$amc" = "m" ]
  115.             then
  116.                 amc1="-mtime $days"
  117.             else
  118.                 amc1="-ctime $days"
  119.             fi
  120.         ;;
  121.         
  122.         *) amc1=""
  123.         ;;
  124.     esac
  125.  
  126. ######################################################
  127.  
  128. echo -n  "$name: command? (don't end with \;) "
  129. read command
  130.  
  131.     if [ "$command" != "" ]
  132.     then
  133.         echo -n  "$name: confirm command? [y/N] "
  134.         stty cbreak
  135.         confirm=`dd if=/dev/tty bs=1 count=1 2>/dev/null`
  136.         stty -cbreak
  137.         
  138.         case $confirm in
  139.             y*|Y*) 
  140.                command1="-ok $command "
  141.                echo " "
  142.             ;;
  143.  
  144.             *) command1="-exec $command "
  145.             ;;
  146.         esac
  147.     fi
  148.  
  149. ######################################################
  150. echo -n "$name: print? [y/N] "
  151.     stty cbreak
  152.     print=`dd if=/dev/tty bs=1 count=1 2>/dev/null`
  153.     stty -cbreak
  154.     
  155.     case $print in 
  156.         
  157.         y|Y) print1="-print"
  158.              echo " "
  159.         ;;
  160.         
  161.         *)   print1=""
  162.         ;;
  163.     esac
  164.  
  165. ######################################################
  166. echo -n "$name: list? [y/N] "
  167.     stty cbreak
  168.     list=`dd if=/dev/tty bs=1 count=1 2>/dev/null`
  169.     stty -cbreak
  170.     
  171.     case $list in 
  172.         
  173.         y|Y) list1="-ls"
  174.              echo " "
  175.         ;;
  176.         
  177.         *)   list1=""
  178.         ;;
  179.     esac
  180.  
  181. ######################################################
  182. ######################################################
  183.  
  184. if [ "$all" = "yes" ]     # if the user wants to match all files
  185. then        
  186.     if [ "$command1" != "" ]
  187.     then    
  188.         find $dir -name "*" $type1 $user1 $amc1 $command1 \; $print1 $list1
  189.     else
  190.         find $dir -name "*" $type1 $user1 $amc1 $print1 $list1
  191.     fi
  192. else
  193.     if [ "$wildcard" = "yes" ]
  194.     then
  195.         # if the user DOES NOT want just exact matches
  196.         if [ "$command1" != "" ]
  197.         then    
  198.            find $dir $filename1\* $type1 $user1 $amc1 $command1 \; $print1 $list1
  199.         else
  200.             find $dir $filename1\* $type1 $user1 $amc1 $print1 $list1
  201.         fi
  202.     else
  203.         # if the user DOES want to use just exact matches
  204.         if [ "$command1" != "" ]
  205.         then    
  206.               find $dir $filename1 $type1 $user1 $amc1 $command1 \; $print1 $list1
  207.         else
  208.             find $dir $filename1 $type1 $user1 $amc1 $print1 $list1
  209.         fi
  210.     fi
  211. fi
  212.  
  213. exit 0
  214. # end